package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Formalities;
import com.ruoyi.system.service.IFormalitiesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 手续Controller
 * 
 * @author ruoyi
 * @date 2021-04-29
 */
@RestController
@RequestMapping("/system/formalities")
public class FormalitiesController extends BaseController
{
    @Autowired
    private IFormalitiesService formalitiesService;

    /**
     * 查询手续列表
     */
//    @PreAuthorize("@ss.hasPermi('system:formalities:list')")
    @GetMapping("/list")
    public TableDataInfo list(Formalities formalities)
    {
        startPage();
        List<Formalities> list = formalitiesService.selectFormalitiesList(formalities);
        return getDataTable(list);
    }

    /**
     * 导出手续列表
     */
//    @PreAuthorize("@ss.hasPermi('system:formalities:export')")
    @Log(title = "手续", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Formalities formalities)
    {
        List<Formalities> list = formalitiesService.selectFormalitiesList(formalities);
        ExcelUtil<Formalities> util = new ExcelUtil<Formalities>(Formalities.class);
        return util.exportExcel(list, "手续数据");
    }

    /**
     * 获取手续详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:formalities:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(formalitiesService.selectFormalitiesById(id));
    }
    /**
     * 新增营业执照材料
     */
    @Log(title = "手续", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Formalities formalities)
    {
        return toAjax(formalitiesService.insertFormalities(formalities));
    }

    /**
     * 修改手续
     */
//    @PreAuthorize("@ss.hasPermi('system:formalities:edit')")
    @Log(title = "手续", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Formalities formalities)
    {
        return toAjax(formalitiesService.updateFormalities(formalities));
    }

    /**
     * 删除手续
     */
//    @PreAuthorize("@ss.hasPermi('system:formalities:remove')")
    @Log(title = "手续", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(formalitiesService.deleteFormalitiesByIds(ids));
    }
}
